import axios from '@/libs/api.request'

export const upBase64 = (base64) => {
  return axios.request({
    url: 'https://txy.juyouhx.com/Api/Api/upBase64ToOss',
    data: { base64: base64 },
    method: 'post',
    php: true
  })
}

// 获取全国省市信息，传参为省列表，传省级code查询对应市级
export const getCityList = (data) => {
  return axios.request({
    url: '/api/as/sc/city/arealist',
    data: data,
    method: 'post'
  })
}

// 上传图片到民政生产服务器
export const uploadPic = (data) => {
  return axios.request({
    // url: 'http://10.40.20.11:5000/api/uc/csc/auditOrderService/uploadPic',
    url: '/api/uc/mzsc/uploadService/uploadPic',
    data: data,
    method: 'post'
  })
}

export const imgComparison = (img1, img2) => {
  return axios.request({
    url: '/api/uc/csc/faceCompareService/createFaceCompare',
    data: { type: 2, value1: img1, value2: img2 },
    method: 'post'
  })
}

export const formBuild = () => {
  return axios.request({
    url: '/api/cln/csc/autoItemForm/testform',
    method: 'get'
  })
}
export const createUpLoadFiles = (url, data) => {
  return axios.request({
    url: url,
    data: data,
    method: 'post'
  })
}
export const getSign = (data) => {
  return axios.request({
    url: '/api/ac/csc/auditHadoopUploadFilesService/getSign',
    data: data,
    method: 'post'
  })
}
export const updateUserGPY = (data) => {
  return axios.request({
    url: '/api/ac/sc/systemUserService/updateUserGPY',
    data: data,
    method: 'post'
  })
}
// 一级残疾人身份验证接口
export const disabilityInfoVerify = (data) => {
  return axios.request({
    url: '/api/uc/csc/auditOrder3rdService/disabilityInfoVerify',
    data: data,
    method: 'post'
  })
}
// 重复申请验证接口
export const repetitionApply = (data) => {
  return axios.request({
    url: '/api/uc/csc/auditOrder3rdService/repetitionApply',
    data: data,
    method: 'post'
  })
}

// 获取用户基本信息
export const getUserInfoByLoginName = (data) => {
  return axios.request({
    url: '/api/ac/sc/systemUserService/getUserInfoByLoginName',
    data: data,
    method: 'post'
  })
}

// 初始化账号基本信息
export const updateResetAccount = (data) => {
  return axios.request({
    url: '/api/ac/sc/systemUserService/updateResetAccount',
    data: data,
    method: 'post'
  })
}
// 字典表接口
export const getDictList = (data) => {
  return axios.request({
    url: '/api/as/sc/dict/getDictList',
    method: 'post',
    data: data
  })
}
// 压缩图片
export function compressImg (file) {
  // var src = ''
  // var files = ''
  var fileSize = parseFloat(parseInt(file['size']) / 1024 / 1024).toFixed(2)
  var read = new FileReader()
  read.readAsDataURL(file)
  return new Promise(function (resolve, reject) {
    read.onload = function (e) {
      var img = new Image()
      img.src = e.target.result
      img.onload = function () {
        // 默认按比例压缩
        var w = this.width
        var h = this.height
        // 生成canvas
        var canvas = document.createElement('canvas')
        var ctx = canvas.getContext('2d')
        var base64 = ''
        // 创建属性节点
        canvas.setAttribute('width', w)
        canvas.setAttribute('height', h)
        ctx.drawImage(this, 0, 0, w, h)
        if (fileSize < 1) {
          // 如果图片小于一兆 那么不执行压缩操作
          base64 = canvas.toDataURL(file['type'], 1)
          console.log(base64)
        } else if (fileSize > 1 && fileSize < 5) {
          // 如果图片大于1M并且小于2M 那么压缩0.5
          base64 = canvas.toDataURL(file['type'], 0.5)
          console.log(base64, '压缩0.5')
        } else {
          console.log('图片大于2M')
          // 如果图片超过2m 那么压缩0.2
          base64 = canvas.toDataURL(file['type'], 0.2)
          console.log(base64, '压缩0.2')
        }
        // 回调函数返回file的值（将base64编码转成file）
        // files = dataURLtoFile(base64) // 如果后台接收类型为base64的话这一步可以省略
        resolve(base64)
      }
    }
  })
}
